import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
Vue.use(VueRouter)


//解决重复点击导航时报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [{
		path: '/main',
		name: 'Main',
		component: () => import('../views/Main.vue'),
		children: [{
				path: 'cakexq',
				name: 'CakeXq',
				component: () => import('../views/CakeXq.vue'),
			},
			{
				path: 'shopping',
				name: 'Shopping',
				component: () => import('../views/Shopping.vue'),
			},
			{
				path: 'about',
				name: 'About',
				component: () => import('../views/About.vue'),
			},
			{
				path: 'business',
				name: 'Business',
				component: () => import('../views/Business.vue'),
			},
			{
				path: 'handbook',
				name: 'Handbook',
				component: () => import('../views/Handbook.vue'),
			},
			{
				path: 'shalong',
				name: 'Shalong',
				component: () => import('../views/Shalong.vue'),
			},
			{
				path: 'cup',
				name: 'Cup',
				component: () => import('../views/Cup.vue'),
			},
			{
				path: 'makalong',
				name: 'Makalong',
				component: () => import('../views/Makalong.vue'),
			},
			{
				path: 'cake',
				name: 'Cake',
				component: () => import('../views/Cake.vue'),
			},
			{
				path: 'register',
				name: 'Register',
				component: () => import('../views/Register.vue'),
			},
			{
				path: 'login',
				name: 'Login',
				component: () => import('../views/Login.vue'),
			},
			{
				path: 'notfound',
				name: 'NotFound',
				component: () => import('../views/NotFound.vue'),
			},
		]
	},
	{
		path: '/test',
		name: 'test',
		component: () => import('../views/Test.vue'),
		meta:{
			title:"测试"
		},
		children:[
			{
					path: 'textNext',
					name: 'textNext',
					component: () => import('../views/textNext.vue'),
					meta:{
						title:"测试2"
					}
				},
				{
						path: 'textNextTwo',
						name: 'textNextTwo',
						component: () => import('../views/textNextTwo.vue'),
						meta:{
							title:"测试3"
						}
					},
		]
	},
	{
		path: '/groupChat',
		name: 'groupChat',
		component: () => import('../views/groupChat.vue'),
		meta:{
			title:"group"
		},
	},
	{
		path: '/', //路径："/"代表根路径
		name: 'Home', //此路由关系的名称
		component: Home, //组件
		meta: {
			title: "首页"
		}
	},
]
const router = new VueRouter({
	mode: 'history',
	base: process.env.BASE_URL,
	routes
})
router.beforeEach((to, from, next) => {
	if (to.meta.title) {
		document.title = to.meta.title
	}
	next();
});

export default router
